﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MingYuanYun.Context.Abstractions
{
    public static class ServiceContextExtensions
    {
        public static T GetService<T>(this IServiceContext context)
        {
            return context.ServiceProvider.GetRequiredService<T>();
        }

        public static T GetConfig<T>(this IServiceContext context, string sectionName)
        {
            return context.Configuration.GetSection(sectionName).Get<T>();
        }

        public static IServiceScope CreateScope(this IServiceContext context)
        {
            return context.ServiceScopeFactory.CreateScope();
        }
    }
}
